package uk.ac.aber.paws.client.db;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 16th August 2011
 * 
 * DBCall.java
 * 
 * Contains all generic constants used within the application
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.Serializable;
import java.net.Socket;
import java.util.Hashtable;
import java.util.Vector;

public class DBCall implements Serializable   {

	public static final int UPDATE = 1;
	public static final int QUERY = 2;
	
	private int queryType;
	private String storedProc = null;
	private Vector<Object> paramList = null;
	private transient Socket replySocket;
	private boolean responseRequired;
	private Hashtable<String,Object> response = new Hashtable<String,Object>();
	private boolean priority = false;
	
	public DBCall(int queryTypeIn, String storedProcIn, Vector<Object> paramListIn, boolean responseRequired, boolean priority) {
		
		this.queryType = queryTypeIn;
		this.storedProc = storedProcIn;
		this.paramList = paramListIn;
		this.responseRequired = responseRequired;
		this.priority = priority;
	}
	
	public Hashtable<String,Object> getResponse() {
		
		return response;
	}
	
	public boolean getPriority() {
		return priority;
	}
	
	public String getStoredProc() {
		
		return storedProc;
	}
	
	public Vector<Object> getParamList() {
		
		return paramList;
	}
	
	public int getQueryType() {
		
		return queryType;
	}
	
	public boolean getResponseRequired() {
		
		return responseRequired;
	}
	
	public void setResponseRequired(boolean state) {
		
		responseRequired = state;
	}
	
	public void assignReplySocket(Socket socket) {
		
		replySocket = socket;
	}
	
	public boolean isSocketValid() {
		
		if (replySocket != null) {
			return replySocket.isConnected();
		}
		
		return false;
	}
	
	public Socket getReplySocket() {
		return replySocket;
	}
	
	public String toString() {
		
		String tmpString = "";
		
		tmpString = "query="+queryType+",storedProc="+storedProc+",paramList="+this.paramList.toString()+",response="+response.toString();
		
		return tmpString;
	}
}
